package com.dgut.courses_selecting_sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dgut.courses_selecting_sys.entity.Notice;
import com.dgut.courses_selecting_sys.entity.User;
import com.dgut.courses_selecting_sys.mapper.DeptMapper;
import com.dgut.courses_selecting_sys.mapper.NoticeMapper;
import com.dgut.courses_selecting_sys.mapper.UserMapper;
import com.dgut.courses_selecting_sys.service.INoticeService;
import com.dgut.courses_selecting_sys.utils.ShiroUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author yuec
 * @since 2020-09-09
 */
@Service
public class NoticeServiceImpl extends ServiceImpl<NoticeMapper, Notice> implements INoticeService {

    @Autowired
    NoticeMapper noticeMapper;
    @Autowired
    DeptMapper deptMapper;

    /**
     * 获取最新10条数据
     * @return
     */
    @Override
    @Cacheable(value = "notice_Last_new_ten_by_deptId", key = "#deptId")
    public List<Notice> listNewTen(Integer deptId) {
        return noticeMapper.selectListlistNewTen(deptId);
    }

    /**
     * 获取最近3个月的消息
     * @return
     */
    @Override
    public List<Notice> listPassMonth() {
//        long now = System.currentTimeMillis();
//        System.out.println(new Date(now));
//        now -= 3*30*24*60*60*1000;
        Calendar now = Calendar.getInstance();
        now.setTime(new Date());
        now.add(Calendar.MONTH,-3);
        Date timeBefore = now.getTime();

        Integer deptId = ShiroUtils.getSysUser().getDeptId();
        return noticeMapper.selectListlistPassMonth(deptId,timeBefore);
    }

    /**
     * 获取全部消息
     * @return
     */
    @Override
    @Cacheable(value = "notice_list_all_by_deptId", key = "#deptId")
    public List<Notice> listAllNotice(int deptId) {
        return noticeMapper.selectListlistAllNotice(deptId);
    }
}
